import 'package:flutter/widgets.dart';

import '../public.dart';

/// 独立弹起输入框容器
class PopInputBoxComponent extends StatefulWidget {
  final Widget child;
  PopInputBoxComponent({Key key, this.child}) : super(key: key);

  @override
  PopInputBoxComponentState createState() => PopInputBoxComponentState();
}

class PopInputBoxComponentState extends State<PopInputBoxComponent> {
  bool init = false;

  @override
  void initState() {
    super.initState();

    // WidgetsBinding.instance.addPostFrameCallback((_) async {
    // });
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final bottom = MediaQuery.of(context).viewInsets.bottom;

    // 收起键盘时，关闭弹窗
    if (init && bottom == 0) {
      Navigator.pop(context);
    }

    // 有键盘高度表示初始化好了
    if (bottom != 0 && !init) {
      init = true;
    }

    return Container(
        padding: EdgeInsets.only(bottom: bottom), child: widget.child);
  }
}
